package com.srwl.mytx.widget;


import android.app.AlertDialog;
import android.content.Context;
import android.os.Bundle;
import android.view.View;
import android.view.WindowManager;
import android.widget.EditText;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.srwl.mytx.R;


public class DonationDialog_1 extends AlertDialog {
    private static final String TAG = "NumberInputDialog";

    private String title;
    private View rl_confirm, rl_cancel;

    private ConfirmListener confirmListener;
    private CancleListener cancleListener;
    private EditText et_amount;

    public DonationDialog_1(@NonNull Context context) {
        super(context);
    }

    public DonationDialog_1(@NonNull Context context, int themeResId) {
        super(context, themeResId);
    }

    protected DonationDialog_1(@NonNull Context context, boolean cancelable, @Nullable OnCancelListener cancelListener) {
        super(context, cancelable, cancelListener);
    }


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.layout_donation_dialog);
        getWindow().clearFlags(WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM);//这样虽然键盘能弹起来，但是页面上的 其他含有editText 的视图也会被弹起来，只不过在半透明黑色遮罩后面，还不是很明显
        et_amount = findViewById(R.id.et_donation_amount);


        rl_confirm = findViewById(R.id.rl_confirm);
        rl_confirm.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (confirmListener != null) {
                    confirmListener.confirm(Double.valueOf(et_amount.getText().toString()));
                    dismiss();
                } else {
                    dismiss();
                }
            }
        });

        rl_cancel = findViewById(R.id.rl_cancle);
        rl_cancel.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (cancleListener != null) {
                    cancleListener.cancle();
                    dismiss();
                } else {
                    dismiss();
                }
            }
        });


    }

    public void setConfirmListener(ConfirmListener confirmListener) {
        this.confirmListener = confirmListener;
    }

    public void setCancleListener(CancleListener cancleListener) {
        this.cancleListener = cancleListener;

    }

    public interface ConfirmListener {
        void confirm(double amount);
    }

    public interface CancleListener {
        void cancle();
    }


}
